package top.cdmrx.demo.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.cdmrx.common.R;
import top.cdmrx.demo.edu.entity.Course;
import top.cdmrx.demo.edu.entity.Teacher;
import top.cdmrx.demo.edu.service.CourseService;
import top.cdmrx.demo.edu.service.TeacherService;

import java.util.List;

/**
 * Created by Mr.陈 time on 2021/11/26 | 18:32
 **/
@RestController
@RequestMapping("/edu/indexfront")
@CrossOrigin
public class IndexController {
    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    /**
     * 查询前八门热门课程，和前四条热门讲师
     * @return
     */
    @RequestMapping("index")
    public R index(){
        //查询前八门课程
        QueryWrapper<Course> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id");
        courseQueryWrapper.last("limit 8");
        List<Course> list = courseService.list(courseQueryWrapper);

        //查询前四位热门讲师
        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit 4");
        List<Teacher> list1 = teacherService.list(teacherQueryWrapper);

        return R.success().data("eduList",list).data("teacherList",list1);
    }


}
